Skip to content

fix: standardize tool function docstrings to Google Python style#47

Closed
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen:fix/google-style-docstrings
Closed

fix: standardize tool function docstrings to Google Python style#47
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen:fix/google-style-docstrings

Conversation

@Ridwannurudeen
Copy link

Summary

Closes #14

Rewrites all 11 @tool-decorated function docstrings in functions.py to follow the Google Python Style Guide, which LangChain's _parse_python_function_docstring requires to correctly generate OpenAI tool schemas via convert_to_openai_tool().

Problem

With the old formatting, convert_to_openai_tool() failed to separate the function description from its parameter metadata. The result was tool schemas where:

  • The description field contained the entire docstring (including raw Args:, Returns:, Note:, and Keys: sections)
  • The parameters.properties entries had no description field
  • Multi-tool calls broke because the malformed descriptions confused function dispatch

What changed

Every docstring in functions.py now follows this structure:

"""One-line summary starting on the opening triple-quote line.

Args:
    param_name (type): Description with 4-space indent.

Returns:
    type: Description with 4-space indent.
"""

Specific fixes per function:

Function Issue
code_interpreter Removed Note: section that leaked into description; moved context into Args:
google_search_and_scrape Added missing blank line between Args: and Returns:; fixed return type listdict to match type hint
get_current_stock_price Fixed 2-space indent → 4-space
get_stock_fundamentals Collapsed verbose Keys: block into a single Returns: line
get_financial_statements Fixed 0-space indent → 4-space
get_key_financial_ratios Fixed 0-space indent → 4-space
get_analyst_recommendations Fixed 0-space indent → 4-space
get_dividend_data Fixed 0-space indent → 4-space
get_company_news Fixed 0-space indent → 4-space
get_technical_indicators Fixed 0-space indent → 4-space
get_company_profile Fixed 0-space indent → 4-space

Scope

  • Only docstrings were modified — no functional code changes
  • 42 insertions, 66 deletions (net reduction of 24 lines)
  • All 11 functions processed by get_openai_tools() are covered

Test plan

  • Verified each docstring follows Google style with consistent 4-space indentation
  • Confirmed convert_to_openai_tool() receives properly formatted input
  • No functional code was altered

Closes NousResearch#14

LangChain's `_parse_python_function_docstring` expects docstrings to
follow the Google Python style guide in order to correctly extract
function descriptions and parameter metadata for OpenAI tool schemas.

The existing docstrings in `functions.py` had several formatting issues
that caused `convert_to_openai_tool` to produce malformed tool
definitions:

1. Missing 4-space indentation under Args/Returns sections
   (get_financial_statements, get_key_financial_ratios,
   get_analyst_recommendations, get_dividend_data, get_company_news,
   get_technical_indicators, get_company_profile)

2. Inconsistent 2-space indentation instead of 4-space
   (get_current_stock_price)

3. Note section leaking into tool description
   (code_interpreter)

4. Detailed Keys block under Returns parsed as description text
   (get_stock_fundamentals)

5. Missing blank line between Args and Returns sections
   (google_search_and_scrape)

6. Return type mismatch between docstring (list) and type hint (dict)
   (google_search_and_scrape)

All 11 @tool-decorated functions now follow a consistent format:
- Summary on the opening line (no blank line after triple quotes)
- 4-space indented Args section with (type) annotations
- 4-space indented Returns section
- Blank line separating each section
- No extraneous sections (Note, Keys) that confuse the parser
@Ridwannurudeen
Copy link
Author

Friendly ping — this fixes #14 by standardizing all 11 tool docstrings to Google Python style so convert_to_openai_tool() generates correct schemas. No functional code changes, just docstring formatting. Happy to adjust if needed.

@Ridwannurudeen
Copy link
Author

Closing as superseded by #49.

@Ridwannurudeen
Copy link
Author

Superseded by #49, which contains runtime correctness fixes plus regression tests. Closing this PR to focus review on the higher-impact changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

This Repo needs some refactoring for the function calling to work properly

1 participant